// vite.config.js

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
const { proxyUrl } = require("./src/config");

// https://vitejs.dev/config/
export default defineConfig({
  lintOnSave: false,
  plugins: [vue()],
  resolve: {
    // 配置路径别名
    alias: {
      "@": path.resolve(__dirname, "src"),
      views: "@/views",
      assets: "@/assets",
      common: "@/common",
      components: "@components",
      network: "@/network",
      router: "@/router",
      store: "@/store",
    },
    // 省略文件后缀
    extensions: ["", ".js", ".json", ".vue", ".scss", ".css"],
  },
  server: {
    // 修改端口
    port: 8888,
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: proxyUrl,
        changeOrigin: true,
        logLevel: "debug",
        pathRewrite: {
          "^/api": proxyUrl, // 路径重写
        },
        cookieDomainRewrite: "localhost",
      },
    },
  },
  compilerOptions: {
    target: "esnext",
    useDefineForClassFields: true,
    module: "esnext",
    moduleResolution: "node",
    strict: true,
    jsx: "preserve",
    sourceMap: true,
    resolveJsonModule: true,
    esModuleInterop: true,
    lib: ["esnext", "dom"],
    baseUrl: ".",
    paths: {
      "@/*": ["src/*"],
    },
    skipLibCheck: true,
  },
  include: ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
});
